package com.qudian.pay.core.exception;

/**
 * @Description: 运行时异常
 * @ClassName: QDRuntimeException
 * @author gaoxiang
 * @date 2016年5月17日 下午2:46:26
 */ 
public class QDRuntimeException extends RuntimeException {
	
	private static final long serialVersionUID = -3093884695580333320L;

	/**
	 * @Fields errorCode : 错误编码
	 */ 
	private int errorCode;
	
	/**
	 * @Fields message : 消息
	 */ 
	private String message;
	
	/**
	 * @Fields parameters : 扩展参数
	 */ 
	private Object[] parameters;
	
	public QDRuntimeException(String message,Throwable cause) {
		super(message,cause);
	}
	
	public QDRuntimeException(Throwable cause) {
		super(cause);
	}
	
	public QDRuntimeException(int errorCode) {
		this.errorCode = errorCode;
	}
	
	public QDRuntimeException(int errorCode, String message) {
		this.message = message;
		this.errorCode = errorCode;
	}
	
	public QDRuntimeException(int errorCode, Throwable cause) {
		super(cause);
		this.errorCode = errorCode;
	}
	
	public QDRuntimeException(int errorCode, String message, Throwable cause) {
		super(cause);
		this.errorCode = errorCode;
		this.message = message;
	}
	
	public QDRuntimeException(int errorCode, Object... args) {
		this.errorCode = errorCode;
		this.parameters = args;
	}
	
	public QDRuntimeException(int errorCode, String message, Object... args) {
		this.errorCode = errorCode;
		this.message = message;
		this.parameters = args;
	}
	
	public QDRuntimeException(int errorCode, Throwable cause, Object... args) {
		super(cause);
		this.errorCode = errorCode;
		this.parameters = args;
	}
	
	public QDRuntimeException(int errorCode, String message, Throwable cause, Object... args) {
		super(cause);
		this.errorCode = errorCode;
		this.message = message;
		this.parameters = args;
	}
	
	public int getErrorCode() {
		return errorCode;
	}
	
	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}
	
	public String getMessage() {
		if (null == message) {
			return String.valueOf(this.errorCode);
		}
		return this.errorCode + " | msg=" + message;
	}
	
	public void setMessage(String message) {
		this.message = message;
	}
	
	public Object[] getParameters() {
		return parameters;
	}
	
	public void setParameters(Object... parameters) {
		this.parameters = parameters;
	}
	
	public String toString() {
		String className = getClass().getName();
		if(message != null){
			className += ": errorCode = " + errorCode + ": message = " + getLocalizedMessage();
		}
		return className;
	}
}
